<?php

namespace App\Admin\Actions\Post;

use App\Model\UserProfile;
use Encore\Admin\Actions\BatchAction;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class UpdateWages extends BatchAction
{
    public $name = '修改单价：【空/0表示不对该项进行修改】';
    protected $selector = '.report-posts';

    public function handle(Collection $collection, Request $request)
    {
        $coin_setting = $request->input('coin_setting', 0);
        $video_coin_setting = $request->input('video_coin_setting',0);
        $chat_coin_setting = $request->input('chat_coin_setting', 0);
        if ($coin_setting && !$video_coin_setting && $chat_coin_setting) {
            return $this->response()->error('未做任何修改')->refresh();
        }
        $data = [];
        $coin_setting && $data['coin_setting'] = $coin_setting;
        $video_coin_setting && $data['video_coin_setting'] = $video_coin_setting;
        $chat_coin_setting && $data['chat_coin_setting'] = $chat_coin_setting;
        $ids = $request->input('_key');
        $ids = explode(',', $ids);
        UserProfile::updateWagesByUserIds($ids, $data);
        return $this->response()->success('修改成功')->refresh();
    }

    public function form()
    {
        $this->integer('coin_setting', '语音收费(金币/分钟)')->rules("Lt:200");
        $this->integer('video_coin_setting', '视频收费(金币/分钟)')->rules("Lte:200");
        $this->integer('chat_coin_setting', '私聊收费(金币/分钟)')->rules("Lt:200");
    }

    public function html()
    {
        return "<a class='report-posts btn btn-sm btn-info'><i class='fa fa-info-circle'></i>修改单价</a>";
    }
}
